package org.jeecg.modules.demo.zyHazardInvestigationFather.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.common.system.base.controller.JeecgController;
import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.modules.demo.zyHazardInvestigationFather.entity.ZyHazardInvestigationFather;
import org.jeecg.modules.demo.zyHazardInvestigationFather.service.IZyHazardInvestigationFatherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;
import java.util.List;

 /**
 * @Description: 整改监督父级
 * @Author: jeecg-boot
 * @Date:   2025-07-22
 * @Version: V1.0
 */
@Tag(name ="整改监督父级")
@RestController
@RequestMapping("/zyHazardInvestigationFather/zyHazardInvestigationFather")
@Slf4j
public class ZyHazardInvestigationFatherController extends JeecgController<ZyHazardInvestigationFather, IZyHazardInvestigationFatherService> {
	@Autowired
	private IZyHazardInvestigationFatherService zyHazardInvestigationFatherService;
	
	/**
	 * 分页列表查询
	 *
	 * @param zyHazardInvestigationFather
	 * @param pageNo
	 * @param pageSize
	 * @param req
	 * @return
	 */
	//@AutoLog(value = "整改监督父级-分页列表查询")
	@Operation(summary ="整改监督父级-分页列表查询", description="整改监督父级-分页列表查询")
	@GetMapping(value = "/list")
	public Result<IPage<ZyHazardInvestigationFather>> queryPageList(ZyHazardInvestigationFather zyHazardInvestigationFather,
								   @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
								   @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
								   HttpServletRequest req) {
        QueryWrapper<ZyHazardInvestigationFather> queryWrapper = QueryGenerator.initQueryWrapper(zyHazardInvestigationFather, req.getParameterMap());
		Page<ZyHazardInvestigationFather> page = new Page<ZyHazardInvestigationFather>(pageNo, pageSize);
		IPage<ZyHazardInvestigationFather> pageList = zyHazardInvestigationFatherService.page(page, queryWrapper);
		return Result.OK(pageList);
	}
	
	/**
	 *   添加
	 *
	 * @param zyHazardInvestigationFather
	 * @return
	 */
	@AutoLog(value = "整改监督父级-添加")
	@Operation(summary="整改监督父级-添加", description="整改监督父级-添加")
	@RequiresPermissions("zyHazardInvestigationFather:zy_hazard_investigation_father:add")
	@PostMapping(value = "/add")
	public Result<String> add(@RequestBody ZyHazardInvestigationFather zyHazardInvestigationFather) {
		zyHazardInvestigationFatherService.save(zyHazardInvestigationFather);
		return Result.OK("添加成功！");
	}
	
	/**
	 *  编辑
	 *
	 * @param zyHazardInvestigationFather
	 * @return
	 */
	@AutoLog(value = "整改监督父级-编辑")
	@Operation(summary="整改监督父级-编辑", description="整改监督父级-编辑")
	@RequiresPermissions("zyHazardInvestigationFather:zy_hazard_investigation_father:edit")
	@RequestMapping(value = "/edit", method = {RequestMethod.PUT,RequestMethod.POST})
	public Result<String> edit(@RequestBody ZyHazardInvestigationFather zyHazardInvestigationFather) {
		zyHazardInvestigationFatherService.updateById(zyHazardInvestigationFather);
		return Result.OK("编辑成功!");
	}
	
	/**
	 *   通过id删除
	 *
	 * @param id
	 * @return
	 */
	@AutoLog(value = "整改监督父级-通过id删除")
	@Operation(summary="整改监督父级-通过id删除", description="整改监督父级-通过id删除")
	@RequiresPermissions("zyHazardInvestigationFather:zy_hazard_investigation_father:delete")
	@DeleteMapping(value = "/delete")
	public Result<List<String>> delete(@RequestParam(name="id",required=true) String id) {
		zyHazardInvestigationFatherService.removeById(id);
		List<String> strings = zyHazardInvestigationFatherService.removeZyHazardInvestigation(id);
		return Result.OK(strings);
	}
	
	/**
	 *  批量删除
	 *
	 * @param ids
	 * @return
	 */
	@AutoLog(value = "整改监督父级-批量删除")
	@Operation(summary="整改监督父级-批量删除", description="整改监督父级-批量删除")
	@RequiresPermissions("zyHazardInvestigationFather:zy_hazard_investigation_father:deleteBatch")
	@DeleteMapping(value = "/deleteBatch")
	public Result<List<String>> deleteBatch(@RequestParam(name="ids",required=true) String ids) {
		List<String> id = Arrays.asList(ids.split(","));
		this.zyHazardInvestigationFatherService.removeByIds(id);
		List<String> instantIds= zyHazardInvestigationFatherService.removeZyHazardInvestigationids(id);
		return Result.OK(instantIds);
	}
	
	/**
	 * 通过id查询
	 *
	 * @param id
	 * @return
	 */
	//@AutoLog(value = "整改监督父级-通过id查询")
	@Operation(summary="整改监督父级-通过id查询", description="整改监督父级-通过id查询")
	@GetMapping(value = "/queryById")
	public Result<ZyHazardInvestigationFather> queryById(@RequestParam(name="id	",required=true) String id) {
		ZyHazardInvestigationFather zyHazardInvestigationFather = zyHazardInvestigationFatherService.getById(id);
		if(zyHazardInvestigationFather==null) {
			return Result.error("未找到对应数据");
		}
		return Result.OK(zyHazardInvestigationFather);
	}

    /**
    * 导出excel
    *
    * @param request
    * @param zyHazardInvestigationFather
    */
    @RequiresPermissions("zyHazardInvestigationFather:zy_hazard_investigation_father:exportXls")
    @RequestMapping(value = "/exportXls")
    public ModelAndView exportXls(HttpServletRequest request, ZyHazardInvestigationFather zyHazardInvestigationFather) {
        return super.exportXls(request, zyHazardInvestigationFather, ZyHazardInvestigationFather.class, "整改监督父级");
    }

    /**
      * 通过excel导入数据
    *
    * @param request
    * @param response
    * @return
    */
    @RequiresPermissions("zyHazardInvestigationFather:zy_hazard_investigation_father:importExcel")
    @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
    public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
        return super.importExcel(request, response, ZyHazardInvestigationFather.class);
    }

}
